﻿
<?php


// Inclusion du matos
require_once 'systeme/config.php';
require_once 'systeme/db.class.php';
require_once 'systeme/fonctions.php';
require_once 'systeme/cache_fonction.php';

mysql_query("SET NAMES UTF8");




if ($_GET['a'] == 'voir')
{
	$titre ='Lecture d\'un billet - ';
}
elseif ($_GET['a'] == 'categorie')
{
	$titre = $_GET['cat'].' - ';
	}
elseif ($_GET['a'] == 'admin') 
{
    $titre = 'Administration - ';
    }


$messagesParPage = 4;

$retour_total = sql::query('SELECT COUNT(*) AS total FROM billets');
$donnees_total = sql::assoc($retour_total);
$total = $donnees_total['total'];

$nombreDePages = ceil($total / $messagesParPage);

if (isset($_GET['page'])) {
    $pageActuelle = intval($_GET['page']);
    $titre = 'Page '.$pageActuelle.' - ';

    if ($pageActuelle > $nombreDePages) {
        $pageActuelle = $nombreDePages;
    }
}else {
    $pageActuelle = 1; // La page actuelle est la n°1
}

$premiereEntree = ($pageActuelle - 1) * $messagesParPage;


if ( $config->retrieve_cfg('maintenance') == 1) {
echo $config->retrieve_cfg('maintenance_msg');
echo '<br /><br />[ <a href="admin_index.php">Administration</a> ]';
exit;
}

require_once 'systeme/zcode.php';


$nb_bil = sql::assoc(sql::query('SELECT COUNT(*) AS total FROM billets')); 
$nb_com = sql::assoc(sql::query('SELECT COUNT(*) AS total FROM commentaires')); 
$nb_cat = sql::assoc(sql::query('SELECT COUNT(*) AS total FROM categorie')); 


$cat_rs = sql::query("SELECT id_cat, title_cat FROM categorie");



/*
while ($cats = sql::fetch_assoc($cat_rs))
{
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="theme/style.css" type="text/css" media="screen">
<link rel="stylesheet" href="systeme/fshl/styles/COHEN_style.css">
<title><?php if(isset($titre)) { echo $titre; } ?>Dev Blog</title>
<script src="scripts/bbcode.js"></script>
<script src="scripts/jquery.js" type="text/javascript"></script>  
<script src="scripts/jquery.ui.draggable.js" type="text/javascript"></script>  
 <script src="scripts/jquery.alerts.js" type="text/javascript"></script>  
<link href="scripts/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen">  
<script>
function add_smiley_mere(smiley) {
			if(window.opener) {
				if(window.opener.document.getElementById('texte')) {
					window.opener.document.getElementById('texte').value += smiley;
				}
			}
		}
function add_bbcode(bbcode) {
window.opener.document.getElementById('texte').value += bbcode;
}
function OuvrirPop(url,nom,haut,Gauche,largeur,hauteur,options) {
ouvpop=window.open(url,nom,"top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+options);
}


$(document).ready( function() {

				$("#prompt_button").click( function() {
					jPrompt('Mettre uniquement l\'ID de la vidéo :', 'ID de la vidéo', 'Ajout d\'une vidéo Youtube', function(r) {
						if( r ) document.getElementById('texte').value = '<youtube>' + r + '</youtube>';
					});
				});
});

url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);
var ajax_get_error = false;
function ajax_do (url) {
   if (url.substring(0, 4) != 'http') {
      url = base_url + url;
   }
   var jsel = document.createElement('SCRIPT');
   jsel.type = 'text/javascript';
   jsel.src = url;
   document.body.appendChild (jsel);
   return true;
}
function ajax_get (url, el) {
   if (typeof(el) == 'string') {
      el = document.getElementById(el);
   }
   if (el == null) { return false; }
   if (url.substring(0, 4) != 'http') {
      url = base_url + url;
   }
   getfile_url = base_url + 'getfile.php?url=' + escape(url) + '&el=' + escape(el.id);
   ajax_do (getfile_url);
   return true;
}

function submit_form() {
   
   // on set les variables
   var name = document.getElementById('name').value;
   var email = document.getElementById('email').value;
   var comment = document.getElementById('comment').value;
   
   //on envoie vers le fichier contact_forum-check.php
   url = 'contact_forum-check.php?name=' + escape(name) + '&email=' + escape(email) + '&comment=' + escape(comment);
   
   // on renvoie les résultats dans le div id result
   ajax_get (url, 'result');
} 
</script>
</head>
<body>

<div id="head">
<br />
	<h1><a href="index.php"><?php echo $config->retrieve_cfg('blog_title'); ?></a></h1>

	</div>
	<div id="nav">
<a href="?a=admin">Admin</a>
</div>
<div id="gauche">
<div id="block">
<h4>Navigation</h4>
<ul>
<li><a href="#">Accueil</a></li>
<li><a href="?a=forums">Forums</a></li>
<li><a href="#">Accueil</a></li>
<li><a href="#">Accueil</a></li>
<li><a href="#">Accueil</a></li>
</ul></div>
<div id="block">
<h4>Catégories</h4>
<ul>
<?php

while ($cats = sql::assoc($cat_rs))
{
echo '<li><a href="?a=categorie&amp;id='.$cats['id_cat'].'&amp;cat='.$cats['title_cat'].'">'.$cats['title_cat'].'</a>';
}
?>
</ul></div>

</div>
<!--<div style=" background-color: #eaecf6; margin-left: 160px; margin-right: 70%; font-size: 0.8em; margin-bottom: 15%;">-->
<div id="corps">
<?php




if ($_GET['a'] == 'voir')
{
include './frames/billet.php';
}
elseif ($_GET['a'] == 'categorie')
{
include './frames/categories.php';
}
elseif ($_GET['a'] == 'admin')
{
include './frames/admin_blog.php';

}
elseif($_GET['a'] == 'forums')
{
    include './index_forum.php';
    }
    
    elseif($_GET['a'] == 'contact')
    {
    include './frames/contact.php';
    }
else
{

$req = sql::query("SELECT * , count(com_postid) AS nb_com, count(post_id) AS nb_billets FROM billets LEFT JOIN commentaires on billets.post_id = commentaires.com_postid GROUP BY billets.post_id ORDER BY post_id DESC LIMIT " . $premiereEntree . ", " . $messagesParPage);
$donnees = array();
while ( $ligne = SQL::assoc($req))
{
?>
<div id="article">
<h4><?php echo $ligne['title']; ?></h4>
<p>
<?php
if (!empty($ligne['intro']))
{
	echo smile(parse($ligne['intro'])); 
	echo '<br /><br /><a href="?a=voir&amp;id='.$ligne['post_id'].'" title="Lire la suite de '.$ligne['title'].'">Lire la suite...</a></p>';
}
else {

	echo smile(parse($ligne['body']));
	}
?>
</p>
<div id="art_infos"><span class="gauche"><img src="theme/img/box.png" style="vertical-align: middle center; border: 0;" />&nbsp;<strong><?php echo fetch_categorie($ligne['post_categorie']); ?></strong> | <img src="theme/img/cal.png" alt="" />&nbsp; le 13 janvier 2009 | <img src="theme/img/users.png" alt="" />&nbsp;par Tony | <a href="?a=voir&id=<?php echo $ligne['post_id']; ?>#comments"><img src="theme/img/icon-comment.png" alt="comments" style="vertical-align: middle; border: 0; padding-top: 0.3em;" />&nbsp;<?php echo $ligne['nb_com']; ?></a></span></div>
</div>

<?php
}

echo '<div style="text-align: center;">';
for($i = 1; $i <= $nombreDePages; $i++) { // On fait notre boucle

    echo '<a href="?page='.$i.'">'.$i.'</a>&nbsp;&nbsp;';

	}

echo '</div>';
?>
<div id="foot"><br />
<img src="theme/img/xhtml.png" alt="Valide XHTML" />&nbsp;<img src="theme/img/css.png" alt="Valide CSS" /> <br /></div>


<?php
}


?>

</body></html>
